// pages/store_details/store_details.js
const app = getApp();
var request = require("../../utils/request.js");
var wx_alert = require("../../utils/wx_alert.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrls:[
    ],
    store_list:[    
    ],
    show_have: true,
    img_url: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    app.bindUser(options);//绑定上下级
    if (options.storeId){
      wx.setStorageSync('storeId', options.storeId)
    }

    //快捷导航跳转
    this.turn = request.turn;
    this.close_modal = request.close_modal;

    request.request(app.globalData.getStoreDetail, { storeId: options.storeId},function(res){
      console.log(res)
      if(res.code == 0){
        that.setData({
          imgUrls: res.bannerList,
          img_url: request.url + "/",
          store: res.store,
          storeCaseList: res.storeCaseList,
          store_list: res.productList,
          storeId: options.storeId
        })
      }else{
        wx_alert.alert(res.msg,function(){
          wx.navigateBack({
            
          })
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var user_info = wx.getStorageSync('totalInfo');
    return {
      title: "云家故事",
      path: "/pages/store_details/store_details?storeId=" + this.data.storeId + "&userId=" + user_info.userId 
    }
  },
  tap_product_detail:function(){
    wx.navigateTo({
      url: '/pages/phone_detail/phone_detail',
    })
  },
  all_lists:function(){
    wx.navigateTo({
      url: '/pages/store_lists/store_lists',
    })    
  },
  call_phone:function(e){
    console.log(e)
    var phone = e.currentTarget.dataset.phone;
    wx.makePhoneCall({
      phoneNumber: phone //仅为示例，并非真实的电话号码
    })
  },
  preview:function(e){
    var types = e.currentTarget.dataset.type;
    var index = e.currentTarget.dataset.index;
    var imgUrls = this.data.imgUrls;
    var storeCaseList = this.data.storeCaseList;
    var preview = [];
    if (types == "banner"){

      for (var i in imgUrls){
        var url = request.url + "/" + imgUrls[i].picId;
        preview.push(url)
      }

    } else if (types == "case"){

      for (var i in storeCaseList) {
        var url = request.url + "/" + storeCaseList[i].picId;
        preview.push(url)
      }

    }
    console.log(preview)
    wx.previewImage({
      current: preview[index], // 当前显示图片的http链接
      urls: preview // 需要预览的图片http链接列表
    })
  },
  choose_address: function () {

    wx.openLocation({
      latitude: Number(this.data.store.lat),
      longitude: Number(this.data.store.lit),
      scale: 18
    })

  }
})